package com.neuedu.ssm;

import com.github.pagehelper.Page;
import com.neuedu.ssm.entity.User;
import com.neuedu.ssm.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;


    /**
     * http://127.0.0.1:8080/ssm/user/list?pageNum=1&pageSize=3
     *
     * ArrayList(Page)
     * @param username
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public Map list(String username, Page<User> page){
        Map map = new HashMap();

        page = userService.selectByConditionPage(username,page);


        map.put("pageNum",page.getPageNum());
        map.put("pageSize",page.getPageSize());
        map.put("total",page.getTotal());
        map.put("pages",page.getPages());
        map.put("data",page.getResult());


        return  map;
    }

}
